package mq;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

/**
 * Created by yijy on 2017/6/16.
 */
public class Producer {
    public static void main(String[] args) throws Exception {
        DefaultMQProducer producer = new DefaultMQProducer("GroupProducer");
        producer.setNamesrvAddr("120.26.130.187:9876");
        producer.setInstanceName("producer");
        producer.start();
        for (int i=0;i<50;i++){
            Message msg ;
            if(i%10==0){
                msg = new Message("TopicTest1","TagB",("Hello TagB RocketMQ"+i).getBytes());
            }else{
                msg = new Message("TopicTest","TagA",("Hello TagA RocketMQ"+i).getBytes());
            }

            SendResult sendResult = producer.send(msg);
            System.out.printf("%s%n",sendResult);
        }
        producer.shutdown();
    }
}
